# -*- coding: utf-8 -*-
"""
股票对比分析脚本
"""

from test.stock_analysis_simulation import StockAnalysisSimulation
from datetime import date

def main():
    # 创建分析器
    simulator = StockAnalysisSimulation()
    
    # 获取推荐股票
    best_stocks = simulator.get_best_stocks_for_analysis(min_days=4)
    start_date = date(2025, 8, 8)
    
    print('🎯 对比分析前5只推荐股票：')
    print('='*80)
    
    results = []
    for i, stock in enumerate(best_stocks[:5], 1):
        stock_code = stock['StockCode']
        print(f'\n{i}. 分析股票 {stock_code}...')
        
        result = simulator.simulate_10_day_analysis(stock_code, start_date)
        if result:
            results.append(result)
    
    # 对比总结
    if results:
        print('\n' + '='*80)
        print('📊 五只股票对比总结')
        print('='*80)
        print('股票代码    总收益率   平均日收益   最大日收益   风险等级')
        print('-'*80)
        
        for r in results:
            total_pct = r['total_profit'] * 100
            avg_pct = r['avg_daily_profit'] * 100
            max_pct = r['max_daily_profit'] * 100
            min_pct = r['min_daily_profit'] * 100
            
            # 计算风险等级
            if abs(max_pct - min_pct) > 10:
                risk = '高风险'
            elif abs(max_pct - min_pct) > 5:
                risk = '中风险'
            else:
                risk = '低风险'
                
            print(f'{r["stock_code"]:<10} {total_pct:+6.2f}%   {avg_pct:+6.2f}%     {max_pct:+6.2f}%     {risk:<8}')
        
        # 找出最佳股票
        best_stock = max(results, key=lambda x: x['total_profit'])
        print(f'\n🏆 最佳收益股票: {best_stock["stock_code"]} (总收益: {best_stock["total_profit"]*100:+.2f}%)')
        
        # 找出最稳定股票
        most_stable = min(results, key=lambda x: abs(x['max_daily_profit'] - x['min_daily_profit']))
        volatility = abs(most_stable['max_daily_profit'] - most_stable['min_daily_profit']) * 100
        print(f'🛡️ 最稳定股票: {most_stable["stock_code"]} (波动率: {volatility:.2f}%)')
        
        print('\n' + '='*80)

if __name__ == "__main__":
    main()
